home *** CD-ROM | disk | FTP | other *** search
- /* */
-
- signal on break_c
- signal on syntax
- Pname="AmiSearch/4.5"
- PRG="AmiSearch"
-
- l="rmh.library";if ~show("L",l) then;if ~addlib(l,0,-30) then exit
- if AddLibrary("rexxsupport.library","rxsocket.library")~=0 then exit
-
- /* open stderr for clean output */
- if ~Open("STDERR","CONSOLE:","W") then STDERR = "STDOUT"
-
- onAmirc=left(address(),6)=="AMIRC."
- TEMPLATE="KEY,TIMEOUT/N,MAXLEN/K/N,SAY/S,HOST/K,URL/S,QUIET/S,BREAK/K/N"
- if onAmirc & arg()==1 & arg(1)=="?" then call err TEMPLATE
-
- /* parse arguments */
- parm.5.value = "ftp.uni-paderborn.de"
- if ~RMH_ReadArgs(TEMPLATE) then do
- msg=fault(,PRG)
- parse var msg d": " msg
- call err msg
- end
-
- if parm.7.flag then do
- PRG="AmsBreak"
- task=GetClip("AmiSearch."parm.7.value)
- if task~="" then call Signal(x2d(task),2**12)
- if task~="" then call info "AmiSearch."parm.7.value "broken."
- else call info "AmiSearch."parm.7.value "not found."
- exit
- end
- else if ~parm.0.flag then call err DosString(116)
-
- if ~IsLibOn("SOCKET") then call err "no TCP/IP stack running."
-
- do id=0 while GetClip("AmiSearch."id)~="";end;
- call SetClip("AmiSearch."id,pragma("ID"))
-
- if parm.2.flag then max=parm.2.value
- else max=80
-
- msg="-----"PRG"."id": '"parm.0.value"' -----"
- msgl=length(msg)
- call info msg,1
-
- /* lookup host */
- if ~parm.6.flag then call info "resolving host..."
- host="ftp.uni-paderborn.de"
- addr=resolve(host)
- if addr==-1 then call err "can't lookup host <"host">."
-
- /* create a socket */
- sock = socket("INET","STREAM")
- if sock<0 then call err "can't create my socket."
-
- /* remote */
- sin.addrFamily = "INET"
- sin.addrPort = 80
- sin.addrAddr = addr
-
- /* timeout? */
- if parm.1.flag then do
- if parm.1.value<=0 then call err "timeout must be greater than 0."
- tim=CreateTimer()
- ts=TimerSignal(tim)
- call SetSocketSignals(or(ts,2**12))
- call StartTimer(tim,parm.1.value)
- end
-
- /* connect */
- if ~parm.6.flag then call info "connecting..."
- if connect(sock,"SIN")<0 then call err "can't connect."
-
- /* request to send*/
- eol="D0A"x
- if ~parm.6.flag then call info "sending request..."
- req= "GET /aminetbin/find?"parm.0.value "HTTP/1.0"eol,
- "User-Agent:" Pname "(AmigaOS ARexx rxsocket.library)"eol||eol
- if send(sock,req)~=length(req) then call err "send error."
-
- /* request result */
- if ~parm.6.flag then call info "receiving result..."
- len=recvline(sock,"BUF")
- if len<0 then do
- call err "recv error."
- exit
- end
- if left(buf,5)~="HTTP/" then do
- call err "bad answer from server."
- exit
- end
- parse var buf "HTTP/"ver code rest"D0A"x
- if code~=200 then do
- call err "server returns an error:"rest "("code")."
- exit
- end
-
- /* skip head */
- go=1
- do while go
- len=RecvLine(sock,"BUF")
- if len<0 then call err "recv error."
- parse var buf b": "rest"D0A"x
- go=(buf~=eol)
- end
-
- /* wait for results */
- if ~parm.6.flag then call info copies("-",msgl),1
- go=1
- do while go
- len=RecvLine(sock,"BUF",256)
- if len<0 then call err "recv error."
- go=(pos("files matching",buf)=0)
- end
-
- res=word(buf,1)
- if res=0 then call err "no match found."
- else call info res "file(s) found",1
-
- call info left("Name",30) left("Size",5) left("Age",3) "Comment",1
- go=1
- do forever
- len=recvline(sock,"BUF",1024)
-
- if len<0 then call err "recv error."
- if len=0 then leave
-
- if pos("<A HREF",buf)~=1 then
- if pos("<HR><A HREF",buf)~=1 then iterate
-
- parse var buf "A HREF="u">"file"</A>" "A HREF="u">"path"</A>" size week "<A HREF="dummy">" comment "<"
- parse var comment comment "A"x
- if parm.5.flag then do
- if parm.4.flag then u=addpart(parm.4.value,addpart(path,file))
- end
- else u = left(AddPart(path,file),30)
- msg=u left(space(size),5) left(space(week),3) comment
- call info msg,1
- end
- call info copies("-",msgl),1
- call delClip
- exit
-
- info:
- parse arg msg,s
- if onAmirc then
- if s=1 & parm.3.flag then "SAY" msg
- else "ECHO P=" || "1B"x || "b«"PRG"» C=6" msg
- else say PRG":" msg
- return
-
- /* print error to stderr */
- err:
- parse arg msg
- call delClip
- if IsLibOn("SOCKET") then if errno()==4 then msg="timeout"
- if onAmirc then "ECHO P=" || "1B"x || "b«"PRG"» C=6" msg
- else call Writeln(STDERR,PRG":" msg)
- exit
-
- /* controll user break */
- break_c:
- set.errno=0
- call SetSocketBase("SET")
- call err "user break."
-
- syntax:
- msg="Error" ErrorText(rc) "in line" sigl
- if onAmirc then "ECHO P=" || "1B"x || "b«"PRG"» C=6" msg
- else call Writeln(STDERR,PRG":" msg)
- exit
-
- delClip:
- call SetClip("AmiSearch."id)
- return
-
- /* $VER: AmiSearch.rexx 4.5 (15.5.99) */
-